﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.huawei.esdk.tp.professional.eSDKTPProfessionalTerminalConfCtr;
using System.Web.Services.Protocols;
using com.huawei.esdk.tp.professional.Utils;
using com.huawei.esdk.tp.professional.DataType;

namespace com.huawei.esdk.tp.professional.local
{
    public partial class TerminalConferenceCtrlServiceEx
    {
        private static string url = com.huawei.esdk.tp.professional.Utils.UtilsSettings.URL + com.huawei.esdk.tp.professional.Utils.UtilsSettings.tpProfessionalTerminalConfCtr;
        private static TPProfessionalTerminalConfCtrService terminalConfCtrService = new TPProfessionalTerminalConfCtrService(url);

        private static TerminalConferenceCtrlServiceEx instance = null;
        protected TerminalConferenceCtrlServiceEx()
        {

        }
        public static TerminalConferenceCtrlServiceEx Instance()
        {
            if (null == instance)
            {
                instance = new TerminalConferenceCtrlServiceEx();
            }
            return instance;
        }

        public int requestChairEx(string siteUri)
        {
            try
            {
                terminalConfCtrService.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = terminalConfCtrService.requestChairEx(siteUri);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        public int releaseChairEx(string siteUri)
        {
            try
            {
                terminalConfCtrService.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = terminalConfCtrService.releaseChairEx(siteUri);
                return resultCode;

            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }

        }

        /// <summary>
        /// 查询会场所在会议是否存在密码
        /// </summary>
        /// <param name="siteUri">会场URI</param>
        /// <returns></returns>
        public TPSDKResponseEx<int?> queryConfCtrlPwdEx(string siteUri)
        {
            TPSDKResponseEx<int?> resp = new TPSDKResponseEx<int?>();
            try
            {
                terminalConfCtrService.CookieContainer = AuthorizeServiceEx.cookieJar;
                string result;
                int resultCode = terminalConfCtrService.queryConfCtrlPwdEx(siteUri, out result);

                resp.resultCode = resultCode;
                if (0 == resultCode)
                {
                    resp.result = Convert.ToInt32(result);
                }
                else
                {
                    resp.result = null;
                }

                return resp;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }
        }

        public TPSDKResponseEx<BroadInfoEx> queryBroadInfoEx(string siteUri)
        {
            TPSDKResponseEx<BroadInfoEx> resp = new TPSDKResponseEx<BroadInfoEx>();
            try
            {
                terminalConfCtrService.CookieContainer = AuthorizeServiceEx.cookieJar;

                BroadInfoEx broadInfoEx;
                int resultCode = terminalConfCtrService.queryBroadInfoEx(siteUri, out broadInfoEx);

                resp.resultCode = resultCode;
                resp.result = 0 == resultCode ? broadInfoEx : null;
                return resp;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                resp.resultCode = errorCode;
                return resp;
            }
        }

        public int setRecordBroadEx(string siteUri, int action)
        {
            try
            {
                terminalConfCtrService.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = terminalConfCtrService.setRecordBroadEx(siteUri, action);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }
        }

        public int setDirectBroadEx(string siteUri, int action)
        {
            try
            {
                terminalConfCtrService.CookieContainer = AuthorizeServiceEx.cookieJar;
                int resultCode = terminalConfCtrService.setDirectBroadEx(siteUri, action);
                return resultCode;
            }
            catch (SoapHeaderException e)
            {
                return ExceptionUtils.processSoapException(e);
            }
        }
    }
}
